<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('餐厅管理列表')"/>
    <th:block th:include="include :: select2-css"/>
    <style>
        .img-circle {
            border-radius: 10%;
        }
    </style>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>绑定用户：</label>
                            <select type="text" class="form-control" name="canteenUid" id="canteenUid">
                                <option value="">所有</option>
                            </select>
                        </li>
                        <li>
                            <label>餐厅状态：</label>
                            <select name="canteenState" th:with="type=${@dict.getType('farm_state')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>名称：</label>
                            <input type="text" name="canteenName"/>
                        </li>
                        <li>
                            <label>联系人：</label>
                            <input type="text" name="canteenWorker"/>
                        </li>
                        <li>
                            <label>联系电话：</label>
                            <input type="text" name="canteenPhone"/>
                        </li>
                        <li>
                            <a class="btn btn-primary  btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning  btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="wechat:WxCanteen:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="wechat:WxCanteen:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('wechat:WxCanteen:edit')}]];
    var removeFlag = [[${@permission.hasPermi('wechat:WxCanteen:remove')}]];
    var canteenStateDatas = [[${@dict.getType('farm_state')}]];
    var prefix = ctx + "wechat/WxCanteen";

    $(function () {
        var options = {
            url: prefix + "/list",
            detailUrl: prefix + "/detail/{id}",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "餐厅管理",
            columns: [
                {
                    checkbox: true
                },
                {
                    field: 'canteenId',
                    title: '编号',
                    visible: false,
                    sortable: false
                },
                {
                    field: 'canteenPic',
                    title: '封面图',
                    sortable: false,
                    formatter: function (value, row, index) {
                        return $.table.imageView(value, 200);
                    }
                },
                {
                    field: 'canteenUid',
                    title: '绑定用户',
                    sortable: false,
                    formatter: function (value, row, index) {
                        return "用户昵称:" + row.userName + "(ID：" + value + ")";
                    }
                },
                {
                    field: 'canteenState',
                    title: '餐厅状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(canteenStateDatas, value);
                    }
                },
                {
                    field: 'canteenName',
                    title: '名称',
                    sortable: false
                },
                {
                    field: 'canteenDate',
                    title: '营业时间',
                    sortable: false
                },
                {
                    field: 'canteenHost',
                    title: '餐厅地址',
                    sortable: false
                },
                {
                    field: 'canteenWorker',
                    title: '联系人',
                    sortable: false
                },
                {
                    field: 'canteenPhone',
                    title: '联系电话',
                    sortable: false
                },
                {
                    field: 'canteenLable',
                    title: '标签',
                    sortable: false
                },
                {
                    field: 'canteenTime',
                    title: '创建时间',
                    sortable: false
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="openMenu(\'' + row.canteenName + '\',\'' + row.canteenId + '\')">菜单列表</a> ');
                        actions.push('<a class="btn btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.canteenId + '\')">编辑</a> ');
                        actions.push('<a class="btn btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.canteenId + '\')">删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function openMenu(name,id) {
        $.modal.openFullDetail(name+"-菜单", ctx + "wechat/WxCanteenMenu?cid=" + id);
    }

    $.operate.ajaxGet(ctx + "/wechat/user/listAjax", function (result) {
        if (result.data.length == 0) {
            $.modal.alertError("暂无用户")
        }
        var html = "";
        for (var i = 0; i < result.data.length; i++) {
            html += "<option value='" + result.data[i].userId + "'>" + result.data[i].userName + "</option>";
        }
        $("#canteenUid").append(html);
    })
</script>
</body>
</html>
